﻿Imports System.Data.SqlClient

Public Class DatVe
    Inherits DataProvider

    Public Function Lay() As DTO.ThamSo
        Dim thamSo As New DTO.ThamSo
        Dim sql_query As String = "SELECT * from thamso"

        Dim reader = Me.GetData(sql_query)
        If (IsNothing(reader)) Then
            Return Nothing
        End If

        reader.Read()
        thamSo.ThoiGianBayToiThiru = reader.Item("ThoiGianBayToiThiru")
        thamSo.SL_SanBayTrungGianToiDa = reader.Item("SL_SanBayTrungGianToiDa")
        thamSo.ThoiGianNghiTaiSanBayTu = reader.Item("ThoiGianNghiTaiSanBayTu")
        thamSo.ThoiGianNghiTaiSanBayDen = reader.Item("ThoiGianNghiTaiSanBayDen")
        Me.cnn.Close()
        Return (thamSo)
    End Function

    Public Function Luu(ByVal dto As DTO.PhieuDatCho) As Integer
        If String.IsNullOrEmpty(dto._id) Then
            Insert(dto)
        Else
            Dim sql_query As String = "update datve set ChuyenBay_HangVe=""" + dto._chuyenBayHangVe + """, HanhKhach=""" + dto._maHanhKhach + """"
            Return Me.SaveData(sql_query)
        End If
    End Function

    Public Function Insert(ByVal dto As DTO.PhieuDatCho) As Integer
        Dim sql_query As String = "INSERT INTO DatVe(ChuyenBay_HangVe, HanhKhach, NgayDatVe) VALUES('" + dto._chuyenBayHangVe + "','" + dto._maHanhKhach + "','" + Now + "')"
        Return Me.SaveData(sql_query)
    End Function

    Public Function Update(ByVal dto As DTO.PhieuDatCho) As Integer
        Dim sql_query As String = "update datve set ChuyenBay_HangVe=""" + dto._chuyenBayHangVe + """, HanhKhach=""" + dto._maHanhKhach + """ where id = """ + dto._id + """"
        Return Me.SaveData(sql_query)
    End Function


End Class
